$(document).ready(function () {
    layui.use(['element', 'layer'], function () {
        var element = layui.element;
        var layer = layui.layer;

        initServerInfo(layer);
        // 检查服务器软件版本
        setTimeout(checkServerVersion(layer), 5000);

    });
});

function initServerInfo(layer) {

    ajax(
        "/admin/server/getServerInfo", "POST",
        null, true, true, false
    ).done(function(returnData) {
        // console.log(returnData);
        // 获取成功
        $('#main-server-name').html(returnData.serverName);
        $('#main-server-type').html(returnData.serverType);
        $('#main-server-engine').html(returnData.serverEngine);
        $('#main-server-encording').html(returnData.serverEncording);
        $('#main-server-port').html(returnData.serverWebPort);
        $('#main-server-jdk').html("" + returnData.serverJDKVersion);

        var realVersion = $.base64.atob(softVersion);
        var realVersionId = $.base64.atob(softVersionId);

        $('#main-server-version').html("WMS管理平台&nbsp;v" + realVersion + "/版本号" + realVersionId + "<a href=\"#\" style=\"color:#FF5722;\" target=\"_blank\"><b>&nbsp;&nbsp;查看最新版本</a>");
    });

}

function checkServerVersion(layer) {

    ajax(
        "/admin/server/getServerVersion", "POST",
        null, true, true, false
    ).done(function(returnData) {
        // 获取成功
        // 处理服务器软件版本更新
        var realSoftVersionId = $.base64.atob(softVersionId);

        if (returnData.serverVersionId > realSoftVersionId) {
            layer.open({
                title: "发现新版本",
                type: 0,
                content: "版本：&nbsp;&nbsp;&nbsp;v" + returnData.serverVersion + "<br>版本号：" + returnData.serverVersionId
            });
        }
        else {
            // 当前版本已最新
        }
    });

}